<?php require_once 'include/head.php';?>
<!--h_r start-->
    <div class="h_r wd95 mA">
		<ul>
        	<li class="clearfix">
                <span class="fl wd35 texR">
                    账户：　
                </span>
                    <font class="a"><?php echo $user['username'];?></font>　
                    <input class="disB name" type="hidden"id="username" value="<?php echo $user['username'];?>" />
                <input class="disB name"  type="hidden"id="from_user_id" value="<?php echo $user['id'];?>" />
            </li>
            <li class="clearfix">
                <span class="fl wd35 texR">
                    佣金余额：　
                </span>
                <span class="fl">
                    <font class="a"><?php echo $user['balance'];?></font>
                    <input class="disB name"  type="hidden"id="balance" value="<?php echo $user['balance'];?>" />
                </span>
            </li>
            <li class="clearfix">
                <span class="fl wd35 texR">
                    报单币余额：　
                </span>
                <span class="fl">
                    <font class="a"><?php echo $user['system_balance'];?></font>　
                    <input class="disB name"  type="hidden"id="system_balance" value="<?php echo $user['system_balance'];?>" />
                </span>
            </li>
             <li class="clearfix">
                <span class="fl wd35 texR">
                    对方账户：　
                </span>
                 <input type="text" class="disB name" id="to_user_name"onchange="check_user()" onblur="check_user()" value=""><span style="color: red;padding-left: 20px;" id="usererror"></span>
                <input type="hidden" class="disB name" id="to_user_id" name="to_user_id" value="">
            </li>
            <li class="clearfix">
                <span class="fl wd35 texR">
                    对方姓名：　
                </span>
                <input type="text" class="disB name" id="to_true_name" name="to_true_name"  value="">
            </li>
            
            <li class="clearfix">
                <span class="fl wd35 texR">
                    转账金额：　
                </span>
                <input class="disB name" id="money" type="text" placeholder="" />
            </li>
            <li class="clearfix">
                <span class="fl wd35 texR" style="padding-top: 10px;">
                    扣款方式:　
                </span>
                <input style="width:16px;display:inline-block;margin:10px auto;" type="radio"id="kou" name="kou" checked="checked" value="system" />报单币
                

            </li>
             <li class="clearfix">
                <span class="fl wd35 texR">
                    备注：　
                </span>
                 <textarea class="disB name" id="remark"  placeholder="" ></textarea>
            </li>
            <li class="clearfix">
            	<div class="clearfix">
                    <span class="fl wd35 texR">
                        密码：　
                    </span>
                    <input class="disB name"id="password"name="password" type="password" placeholder="" />
                </div>
                <input class="disB btn cfff font14" onclick="check();" id="zbtn" type="button" value="确认转账" >
            </li>
        </ul>
    </div>
<!--h_r end-->
</body>
<script type="text/javascript">
        function check_user(){
            var to_user_name = document.getElementById("to_user_name").value;
            var from_user_id=document.getElementById("from_user_id").value;
             var data = {username:to_user_name,from_user_id:from_user_id};
            if(to_user_name !=null && to_user_name !=''){
                 $.ajax({
                    url:"/wap/system_zhuan/check_user",
                    async: false,
                    type:"post",
                    data: data,
                    dataType: 'json',
                    success:function(data) {
                        if(data.success=='1'){
                            $("#to_user_id").val(data.user['id']);
                            $("#to_true_name").val(data.user['true_name']);
                            $("#usererror").html('');
                        }else{
                            $("#usererror").html(data.error);
                            $("#to_user_id").val('');
                            $("#to_true_name").val('');
                            $("to_user_name").var('');
                        } 
                    }	
		});
            }
        }
	function check() {
	   var password = document.getElementById("password").value;
           var username = document.getElementById("username").value;
           var money = document.getElementById("money").value;
                money=parseFloat(money);
           var balance=document.getElementById("balance").value;
           balance=parseFloat(balance);
           var system_balance=document.getElementById("system_balance").value;
            
            system_balance=parseFloat(system_balance);
	   var from_user_id=document.getElementById("from_user_id").value;
           var to_user_id=document.getElementById("to_user_id").value;
	   var bool = true;
           var kou=$("input[name='kou']:checked").val();
           var remark=$("#remark").val();
           var data = {password:password,username:username};
           if(to_user_id ==null || to_user_id==''){
               $.alert({
			    title: '提示',
			    content:'转账账户不能为空',
			    confirm: function(){
			    }
			});
                        return false;
           }
           if(to_user_id ==from_user_id){
               $.alert({
			    title: '提示',
			    content:'不能给自己转账',
			    confirm: function(){
			    }
			});
                        return false;
           }
	   if(password ==  null ||password == '') {
		   $.alert({
			    title: '提示',
			    content:'密码不能为空',
			    confirm: function(){
			    }
			});
	        return false;
	   }
           if(money ==  null ||money == '') {
		   $.alert({
			    title: '提示',
			    content:'金额不能为空或小于0',
			    confirm: function(){
			    }
			});
	        return false;
	   }
           
           if(balance < money && kou=='money'){
               $.alert({
			    title: '提示',
			    content:'金额不能大于余额',
			    confirm: function(){
			    }
			});
	        return false;
           }
           if(system_balance < money && kou=='system'){
               $.alert({
			    title: '提示',
			    content:'金额不能大于报单币余额',
			    confirm: function(){
			    }
			});
	        return false;
           }
	   $.ajax({
			url:"/wap/system_money/check_password",
			async: false,
			type:"post",
			data: data,
			dataType: 'json',
			success:function(data) {
				bool = data;
			}	
		});
		if(!bool) {
		   	$.alert({
			    title: '提示',
			    content:'密码错误',
			    confirm: function(){
			    }
			});
			 return false;	
		}
			$("#zbtn").attr("disabled", "disabled"); //使按钮不能被点击 
			$("#zbtn").attr("value", "提交中"); //更改按钮上的文字 
            var post_cash={username:username,password:password,money:money,kou:kou,to_user_id:to_user_id,remark:remark}; 
            $.ajax({
			url:"/wap/system_zhuan/add",
			async: false,
			type:"post",
			data: post_cash,
			dataType: 'json',
			success:function(data) {
				if(data.success){
                                   window.location.href='/wap/system_zhuan';
                                }else{
                                    $.alert({
                                        title: '提示',
                                        content:data.msg,
                                        confirm: function(){
											$("#zbtn").removeAttr("disabled"); //使按钮能够被点击 
											$("#zbtn").attr("value", "确认转账"); //更改按钮上的文字 
                                        }
                                    });
                                        return false;
                                }
			}	
		});    
	   return true;
	}
        
        
</script>		
</html>